package com.cddx.logistics.controller;

import com.cddx.logistics.domain.pojo.Menu;
import com.cddx.logistics.service.MenuService;
import com.cddx.logistics.util.model.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/menu")
@Api(tags = "菜单管理")
public class MenuController {
    @Resource
    MenuService menuService;
    @GetMapping("/getAllMenu")
    @ApiOperation("获取所有菜单")
    public R getAllMenu() { return R.ok(menuService.getAllMenuTree()); }

    @GetMapping("/getMenuByUserId/{userId}")
    @ApiOperation("根据用户id获取菜单")
    public R getMenuByUserId(@PathVariable("userId") Integer userId) {
        return R.ok(menuService.getMenuByUserId(userId));
    }

    @PostMapping("/addMenu")
    @ApiOperation("添加菜单")
    public R addMenu(@RequestBody Menu menu) {
        return R.ok(menuService.addMenu(menu));
    }
}
